package com.feihao.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Mapper
@Component
public interface AccountDao {

    //更新输出方的金额：
    @Update("update account_info set account_balance = account_balance - #{amount} where account_no = #{accountNo}")
    int subtractAccountBalance(@Param("accountNo") String accountNo, @Param("amount") Double amount);

    //更新增加方的金额：
    @Update("update account_info set account_balance = account_balance + #{amount} where account_no = #{accountNo}")
    int addAccountBalance(@Param("accountNo") String accountNo, @Param("amount") Double amount);

    //查询余额：
    @Select("select account_balance from account_info where account_no = #{accountNo}")
    Double queryAccountBalance(@Param("accountNo") String accountNo);

    //查询A的事务号是否存在
    @Select("select count(1) from transaction_info_a where tx_no = #{txNo}")
    int isExistTxA(String txNo);


    //查询B的事务号是否存在
    @Insert("insert into transaction_info_a values(#{txNo},now());")
    int addTxA(String txNo);


    //添加事务号
    @Select("select count(1) from transaction_info_b where tx_no = #{txNo}")
    int isExistTxB(String txNo);


    //添加事务号
    @Insert("insert into transaction_info_b values(#{txNo},now());")
    int addTxB(String txNo);



    //test:

}
